/*    */ package com.lmpop.frame.action;
/*    */ 
/*    */ import java.io.PrintStream;
/*    */ import java.util.Enumeration;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ 
/*    */ public class PageUtil
/*    */ {
/*    */   public String getPageString(String url, int count, int limit, int current, HttpServletRequest req)
/*    */   {
/*  9 */     if (count == 0) return "";
/* 10 */     if (limit == 0) return "";
/* 11 */     String urlhref = urlString(req, url);
/* 12 */     int pageNum = (count - 1) / limit + 1;
/*    */ 
/* 14 */     System.out.println(pageNum);
/*    */ 
/* 16 */     if (current > pageNum) current = pageNum;
/* 17 */     if (current < 0) current = 0;
/* 18 */     int disNum = 8;
/* 19 */     int disHalf = disNum / 2;
/* 20 */     int start = 0; int end = 0;
/*    */ 
/* 22 */     System.out.println(current - disHalf < 0);
/*    */ 
/* 24 */     if (current - disHalf < 0) {
/* 25 */       start = 1;
/* 26 */       end = current + (disNum - current);
/*    */     } else {
/* 28 */       start = current - disHalf;
/* 29 */       if (current + disHalf > pageNum)
/* 30 */         end = pageNum;
/*    */       else {
/* 32 */         end = current + disHalf;
/*    */       }
/* 34 */       if (end == pageNum) {
/* 35 */         start = pageNum - disNum;
/*    */       }
/*    */     }
/*    */ 
/* 39 */     System.out.println(start + "===" + end);
/*    */ 
/* 41 */     StringBuffer sb = new StringBuffer();
/* 42 */     if (pageNum > 1) {
/* 43 */       if (pageNum <= disNum) {
/* 44 */         for (int i = 1; i <= pageNum; i++)
/* 45 */           sb.append(createHref(current, i, urlhref) + "\n");
/*    */       }
/*    */       else {
/* 48 */         for (int i = start; i <= end; i++) {
/* 49 */           sb.append(createHref(current, i, urlhref) + "\n");
/*    */         }
/*    */       }
/*    */     }
/* 53 */     return sb.toString();
/*    */   }
/*    */ 
/*    */   public static void main(String[] args) {
/* 57 */     System.out.println(new PageUtil().getPageString("supply.jsp", 50, 3, 4, null));
/*    */   }
/*    */ 
/*    */   public String createHref(int current, int i, String url) {
/* 61 */     String href = "";
/* 62 */     if (current == i)
/* 63 */       href = "<a href='" + url + "'>[" + i + "]</a>";
/*    */     else {
/* 65 */       href = "<a href='" + url + "'>" + i + "</a>";
/*    */     }
/* 67 */     return href;
/*    */   }
/*    */ 
/*    */   public String urlString(HttpServletRequest req, String url) {
/* 71 */     if (req == null) return url;
/* 72 */     Enumeration reqParamNames = req.getParameterNames();
/* 73 */     StringBuffer sb = new StringBuffer();
/* 74 */     sb.append(url + "?");
/* 75 */     while (reqParamNames.hasMoreElements()) {
/* 76 */       String fieldName = (String)reqParamNames.nextElement();
/* 77 */       String fieldValue = "";
/* 78 */       if (req.getParameter(fieldName) != null) {
/* 79 */         fieldValue = req.getParameter(fieldName);
/*    */       }
/* 81 */       sb.append(fieldName + "=" + fieldValue + "&");
/*    */     }
/*    */ 
/* 84 */     return sb.toString();
/*    */   }
/*    */ }

/* Location:           F:\电商\commons-utils.jar
 * Qualified Name:     com.lmpop.frame.action.PageUtil
 * JD-Core Version:    0.6.0
 */